//
//  NHNavigationController.m
//  LZNeiHan
//
//  Created by 梁梓烽 on 16/9/27.
//  Copyright © 2016年 liangzifeng. All rights reserved.
//

#import "NHNavigationController.h"

@interface NHNavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation NHNavigationController


+(void)initialize
{
    //设置导航条背景颜色
    UINavigationBar  *navigationBar =[UINavigationBar appearance];
    [navigationBar setBarTintColor:[UIColor colorWithRed:0.86f green:0.85f blue:0.80f alpha:1.00f]];
    
    //设置为不透明,去掉bar底部的线条
    [navigationBar setTranslucent:NO];
    [navigationBar setShadowImage:[UIImage new]];
    [navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    
    //导航条标题属性  字体大小/字体颜色
    NSDictionary *dic =@{NSFontAttributeName:[UIFont systemFontOfSize:17],NSForegroundColorAttributeName:[UIColor colorWithRed:0.42 green:0.33 blue:0.27 alpha:1]};
    [navigationBar setTitleTextAttributes:dic];
    
    
    //设置全局UIBarButtonItem的title样式
    UIBarButtonItem  *barButtonItem =[UIBarButtonItem appearance];
    [barButtonItem setTitleTextAttributes:dic forState:UIControlStateNormal];
    
    
}


-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count>0) {
        //添加全局返回按钮
        UIButton  *backBtn =[UIButton buttonWithType:UIButtonTypeCustom];
        // backBtn.backgroundColor=[UIColor redColor];
        backBtn.contentEdgeInsets =UIEdgeInsetsMake(0, -20, 0, 0);
        [backBtn setImage:[UIImage imageNamed:@"back_neihan"] forState:UIControlStateNormal];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
        [backBtn addTarget:self
                    action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        [backBtn sizeToFit];
        viewController.hidesBottomBarWhenPushed = YES;
    }

    else
    {
        
    }
    
    
    [super pushViewController:viewController animated:animated];
    
    
}


-(void)back
{
    [self popViewControllerAnimated:YES];
}



//全屏返回
-(void)viewDidLoad
{
    UIPanGestureRecognizer *pan =[[UIPanGestureRecognizer alloc]initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(handleNavigationTransition:)];
    pan.delegate = self;
    [self.view addGestureRecognizer:pan];
//    
//    LZFLog(@"%@",self.interactivePopGestureRecognizer);
//    
//    LZFLog(@"%@",self.interactivePopGestureRecognizer.delegate);
    
}

//禁止 导航控制器的根控制器的时候 pan手势不然会出现卡死的状态
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    if (self.viewControllers.count>1) {
        return YES;
    }
    return NO;
}

@end
